package com.tesisutn.restsoft.formatters;

import java.text.ParseException;
import java.util.Locale;
import javax.annotation.Resource;

import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.format.Formatter;
import com.tesisutn.restsoft.dominio.articulo.Marca;
import com.tesisutn.restsoft.persistencia.interfaces.dominio.PersistenciaMarca;
import org.springframework.stereotype.Service;

@Service
public class MarcaFormatter implements Formatter<Marca>{
    @Resource
    private PersistenciaMarca persistencia;
	
	@Override
	public String print(Marca object, Locale locale) {
		return object.getId().toString();
	}

	@Override
	public Marca parse(String text, Locale locale) throws ParseException {
		Long id;
		if(text != null && (id=Long.parseLong(text)) > 0)
			return persistencia.get(id);
		return new Marca();
	}
}